<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta http-equiv="cache-control" content="no-cache">
<title>Genivia - Code Example 3: Publishing a WSDL and service on XMethods</title>
<link href="genivia_tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="genivia_content.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="top">
 <div id="titlearea">
  <table height="72px" width="100%" cellspacing="0" cellpadding="0">
   <tbody>
    <tr>
     <td width="10%">&nbsp;</td>
     <td width="175px"><a href="http://www.genivia.com"><img alt="Genivia" src="GeniviaLogo2_trans_noslogan.png"/></a></td>
     <td class="tab_home"><a href="http://www.genivia.com">Home</a></td>
     <td class="tab_home"><a href="http://www.genivia.com/docs.html">Documentation</a></td>
     <td>
      <div style="float: right; font-size: 18px; font-weight: bold;">Code Example 3: Publishing a WSDL and service on XMethods</div>
      <br>
      <div style="float: right; font-size: 10px;">updated Mon Feb 22 2016</div>
     </td>
     <td width="10%">&nbsp;</td>
    </tr>
   </tbody>
  </table>
 </div>
<!-- Generated by Doxygen 1.8.10 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">Code Example 3: Publishing a WSDL and service on XMethods </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>This example shows you how to publish a Web service. In this case, the example template code obtains an authorization token, saves the tModel with the WSDL URL in the server, and saves the business service information in the server.</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;pubH.h&quot;</span></div>
<div class="line"></div>
<div class="line"><span class="keyword">const</span> <span class="keywordtype">char</span> *server = <span class="stringliteral">&quot;https://uddi.xmethods.net/publish&quot;</span>;</div>
<div class="line"></div>
<div class="line"><span class="keyword">const</span> <span class="keywordtype">char</span> *userid = <span class="stringliteral">&quot;...&quot;</span>; <span class="comment">// user ID to access UDDI server</span></div>
<div class="line"><span class="keyword">const</span> <span class="keywordtype">char</span> *passwd = <span class="stringliteral">&quot;...&quot;</span>; <span class="comment">// password to access UDDI server</span></div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> **argv)</div>
<div class="line">{ </div>
<div class="line">  <span class="comment">// Create a gSOAP context</span></div>
<div class="line">  <span class="keyword">struct </span>soap *soap = soap_new();</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Setup SSL context (optional) to verify server&#39;s credentials</span></div>
<div class="line">  <span class="keywordflow">if</span> (soap_ssl_client_context(soap, SOAP_SSL_DEFAULT, NULL, NULL, <span class="stringliteral">&quot;cacerts.pem&quot;</span>, NULL, NULL))</div>
<div class="line">  { </div>
<div class="line">    soap_print_fault(soap, stderr);</div>
<div class="line">    exit(1);</div>
<div class="line">  }</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Step 1: Get an authorization token from the UDDI server</span></div>
<div class="line">  <a class="code" href="classuddi2____get___u_s_c_o_r_eauth_token.html">uddi2__get_USCOREauthToken</a> get_authToken(soap, userid, passwd);</div>
<div class="line">  <a class="code" href="classuddi2____auth_token.html">uddi2__authToken</a> *authToken = get_authToken.send(server);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Check if authorized</span></div>
<div class="line">  <span class="keywordflow">if</span> (!authToken)</div>
<div class="line">  {</div>
<div class="line">    soap_print_fault(soap, stderr);</div>
<div class="line">    exit(1);</div>
<div class="line">  }</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Authorization info provided by server for this session</span></div>
<div class="line">  <span class="keywordtype">char</span> *authInfo = authToken-&gt;<a class="code" href="classuddi2____auth_token.html#a80233664a282adcde23c4b67d21c26df">authInfo</a>;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Step 2: Create a tModel for the WSDL to be published</span></div>
<div class="line">  <a class="code" href="classuddi2____t_model.html">uddi2__tModel</a> tModel;</div>
<div class="line">  tModel.soap_default(soap);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Create the tModel and service name</span></div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#a50896ff6fd3991a5a379a40ca17cb611">name</a> = soap_new_uddi2__name(soap, -1);</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#a50896ff6fd3991a5a379a40ca17cb611">name</a>-&gt;<a class="code" href="classuddi2____name.html#a794ec88f265f687509d198d6f5babf5a">__item</a> = <span class="stringliteral">&quot;...&quot;</span>;</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#a50896ff6fd3991a5a379a40ca17cb611">name</a>-&gt;<a class="code" href="classuddi2____name.html#aaecbfda04e3d7d56a93350d2ac4f5d38">xml__lang_</a> = <span class="stringliteral">&quot;en&quot;</span>;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Create XMethods description elements (see http://www.xmethods.net/ve2/UDDI.po)</span></div>
<div class="line">  <a class="code" href="classuddi2____description.html">uddi2__description</a> *description = soap_new_uddi2__description(soap, 6);</div>
<div class="line">  description[0].<a class="code" href="classuddi2____description.html#a7c197752f408ab3930c3eca4a0a3cfad">__item</a> = <span class="stringliteral">&quot;SHORT DESCRIPTION: ...&quot;</span>;</div>
<div class="line">  description[0].<a class="code" href="classuddi2____description.html#a7d98dc85873e08e454a7e5d4db96c065">xml__lang_</a> = <span class="stringliteral">&quot;en&quot;</span>;</div>
<div class="line">  description[1].<a class="code" href="classuddi2____description.html#a7c197752f408ab3930c3eca4a0a3cfad">__item</a> = <span class="stringliteral">&quot;SHORT DESCRIPTION: ...&quot;</span>;</div>
<div class="line">  description[1].<a class="code" href="classuddi2____description.html#a7d98dc85873e08e454a7e5d4db96c065">xml__lang_</a> = <span class="stringliteral">&quot;en&quot;</span>;</div>
<div class="line">  description[2].<a class="code" href="classuddi2____description.html#a7c197752f408ab3930c3eca4a0a3cfad">__item</a> = <span class="stringliteral">&quot;USAGE NOTES: ...&quot;</span>;</div>
<div class="line">  description[2].<a class="code" href="classuddi2____description.html#a7d98dc85873e08e454a7e5d4db96c065">xml__lang_</a> = <span class="stringliteral">&quot;en&quot;</span>;</div>
<div class="line">  description[3].<a class="code" href="classuddi2____description.html#a7c197752f408ab3930c3eca4a0a3cfad">__item</a> = <span class="stringliteral">&quot;HOMEPAGE URL: ...&quot;</span>;</div>
<div class="line">  description[3].<a class="code" href="classuddi2____description.html#a7d98dc85873e08e454a7e5d4db96c065">xml__lang_</a> = <span class="stringliteral">&quot;en&quot;</span>;</div>
<div class="line">  description[4].<a class="code" href="classuddi2____description.html#a7c197752f408ab3930c3eca4a0a3cfad">__item</a> = <span class="stringliteral">&quot;CONTACT EMAIL: ...&quot;</span>;</div>
<div class="line">  description[4].<a class="code" href="classuddi2____description.html#a7d98dc85873e08e454a7e5d4db96c065">xml__lang_</a> = <span class="stringliteral">&quot;en&quot;</span>;</div>
<div class="line">  description[5].<a class="code" href="classuddi2____description.html#a7c197752f408ab3930c3eca4a0a3cfad">__item</a> = <span class="stringliteral">&quot;IMPLEMENTATION: ...&quot;</span>;</div>
<div class="line">  description[5].<a class="code" href="classuddi2____description.html#a7d98dc85873e08e454a7e5d4db96c065">xml__lang_</a> = <span class="stringliteral">&quot;en&quot;</span>;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Add the four description elements to the tModel</span></div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#ab88df2a2f8cf527df5cdb1109c32a379">description</a>.push_back(description + 0);</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#ab88df2a2f8cf527df5cdb1109c32a379">description</a>.push_back(description + 1);</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#ab88df2a2f8cf527df5cdb1109c32a379">description</a>.push_back(description + 2);</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#ab88df2a2f8cf527df5cdb1109c32a379">description</a>.push_back(description + 4);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Add an overviewDoc element with description and overviewURL</span></div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#aa96f6ab5e985003a56cc67c72ebc821c">overviewDoc</a> = soap_new_uddi2__overviewDoc(soap, -1);</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#aa96f6ab5e985003a56cc67c72ebc821c">overviewDoc</a>-&gt;soap_default(soap);</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#aa96f6ab5e985003a56cc67c72ebc821c">overviewDoc</a>-&gt;<a class="code" href="classuddi2____overview_doc.html#a95e6eb9e75f33e25de5f717d845dd5a9">description</a>.push_back(soap_new_uddi2__description(soap, -1));</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#aa96f6ab5e985003a56cc67c72ebc821c">overviewDoc</a>-&gt;<a class="code" href="classuddi2____overview_doc.html#a95e6eb9e75f33e25de5f717d845dd5a9">description</a>[0]-&gt;__item = <span class="stringliteral">&quot;WSDL source document&quot;</span>;</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#aa96f6ab5e985003a56cc67c72ebc821c">overviewDoc</a>-&gt;<a class="code" href="classuddi2____overview_doc.html#a95e6eb9e75f33e25de5f717d845dd5a9">description</a>[0]-&gt;xml__lang_ = <span class="stringliteral">&quot;en&quot;</span>;</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#aa96f6ab5e985003a56cc67c72ebc821c">overviewDoc</a>-&gt;<a class="code" href="classuddi2____overview_doc.html#a6e9d296ff70c7dfbd66c9164bd6bbf80">overviewURL</a> = <span class="stringliteral">&quot;http://.../my.wsdl#bindingName&quot;</span>;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Omit identifier bag</span></div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#a693b0e0c934d0c4281b2ab47211ec3ba">identifierBag</a> = NULL;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Add a category with a WSDL-specific keyedReference</span></div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#abf5a65de9eb6c8a2e934d1c055d7dc02">categoryBag</a> = soap_new_uddi2__categoryBag(soap, -1);</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#abf5a65de9eb6c8a2e934d1c055d7dc02">categoryBag</a>-&gt;soap_default(soap);</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#abf5a65de9eb6c8a2e934d1c055d7dc02">categoryBag</a>-&gt;<a class="code" href="classuddi2____category_bag.html#a2e5608a2ffc56ce400d00ccb422ffd00">keyedReference</a>.push_back(soap_new_uddi2__keyedReference(soap, -1));</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#abf5a65de9eb6c8a2e934d1c055d7dc02">categoryBag</a>-&gt;<a class="code" href="classuddi2____category_bag.html#a2e5608a2ffc56ce400d00ccb422ffd00">keyedReference</a>[0]-&gt;tModelKey = <span class="stringliteral">&quot;...&quot;</span>;</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#abf5a65de9eb6c8a2e934d1c055d7dc02">categoryBag</a>-&gt;<a class="code" href="classuddi2____category_bag.html#a2e5608a2ffc56ce400d00ccb422ffd00">keyedReference</a>[0]-&gt;keyName = <span class="stringliteral">&quot;uddi-org:types&quot;</span>;</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#abf5a65de9eb6c8a2e934d1c055d7dc02">categoryBag</a>-&gt;<a class="code" href="classuddi2____category_bag.html#a2e5608a2ffc56ce400d00ccb422ffd00">keyedReference</a>[0]-&gt;keyValue = <span class="stringliteral">&quot;wsdlSpec&quot;</span>;</div>
<div class="line"></div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#ac95db300eb9a2cb8eaec53e2138caabb">authorizedName</a> = <span class="stringliteral">&quot;...&quot;</span>;</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#ad224e4c21571bdffbec2a12931f28980">operator_</a> = <span class="stringliteral">&quot;...&quot;</span>;</div>
<div class="line">  tModel.<a class="code" href="classuddi2____t_model.html#a06daf6ed9914e944205327b8b74b125a">tModelKey</a> = <span class="stringliteral">&quot;...&quot;</span>;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Save the tModel</span></div>
<div class="line">  <a class="code" href="classuddi2____save___u_s_c_o_r_et_model.html">uddi2__save_USCOREtModel</a> save_tModel(soap, tModel);</div>
<div class="line">  <a class="code" href="classuddi2____t_model_detail.html">uddi2__tModelDetail</a> *tModelDetail = save_tModel.send(server, authInfo);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Step 3: Create a new service to be published</span></div>
<div class="line">  <a class="code" href="classuddi2____business_service.html">uddi2__businessService</a> service;</div>
<div class="line">  service.soap_default(soap);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Service name is the tModel name (XMethods)</span></div>
<div class="line">  service.<a class="code" href="classuddi2____business_service.html#a525c43f6b35233d28519c28581804079">name</a>.push_back(tModel.<a class="code" href="classuddi2____t_model.html#a50896ff6fd3991a5a379a40ca17cb611">name</a>);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Add two description elements to the service</span></div>
<div class="line">  service.<a class="code" href="classuddi2____business_service.html#af467ba3b2880f2ad069ffaa883f46b33">description</a>.push_back(description + 4);</div>
<div class="line">  service.<a class="code" href="classuddi2____business_service.html#af467ba3b2880f2ad069ffaa883f46b33">description</a>.push_back(description + 5);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Create binding template</span></div>
<div class="line">  <a class="code" href="classuddi2____binding_template.html">uddi2__bindingTemplate</a> bindingTemplate;</div>
<div class="line">  bindingTemplate.soap_default(soap);</div>
<div class="line">  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#ab1c405e9f39c8106bb9746328a27f47e">tModelInstanceDetails</a> = soap_new_uddi2__tModelInstanceDetails(soap, -1);</div>
<div class="line">  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#ab1c405e9f39c8106bb9746328a27f47e">tModelInstanceDetails</a>-&gt;<a class="code" href="classuddi2____t_model_instance_details.html#aca91debd3081bebea288e1403155f47f">tModelInstanceInfo</a>.push_back(soap_new_uddi2__tModelInstanceInfo(soap, -1));</div>
<div class="line">  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#ab1c405e9f39c8106bb9746328a27f47e">tModelInstanceDetails</a>-&gt;<a class="code" href="classuddi2____t_model_instance_details.html#aca91debd3081bebea288e1403155f47f">tModelInstanceInfo</a>[0]-&gt;instanceDetails = NULL;</div>
<div class="line">  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#ab1c405e9f39c8106bb9746328a27f47e">tModelInstanceDetails</a>-&gt;<a class="code" href="classuddi2____t_model_instance_details.html#aca91debd3081bebea288e1403155f47f">tModelInstanceInfo</a>[0]-&gt;tModelKey = tModel.<a class="code" href="classuddi2____t_model.html#a06daf6ed9914e944205327b8b74b125a">tModelKey</a>;</div>
<div class="line">  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#a60c884a9e5564aa6876fb966ed28ea7f">accessPoint</a> = soap_new_uddi2__accessPoint(soap, -1);</div>
<div class="line">  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#a60c884a9e5564aa6876fb966ed28ea7f">accessPoint</a>-&gt;<a class="code" href="classuddi2____access_point.html#ac24b5a3e341f5bc831c9c82c0413e888">__item</a> = <span class="stringliteral">&quot;...&quot;</span>;</div>
<div class="line">  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#a60c884a9e5564aa6876fb966ed28ea7f">accessPoint</a>-&gt;<a class="code" href="classuddi2____access_point.html#a9f359e4031a9e807552f7e24b600d9c2">URLType</a> = <a class="code" href="uddi__v2_8h.html#a9b7286a3ea396716b3268330c870acf6a5e13983e07c9480e5390e709565b935b">uddi2__URLType__http</a>;</div>
<div class="line">  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#a377291525208916ff237e5338ddc73ef">hostingRedirector</a> = NULL;</div>
<div class="line">  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#ace2ae063fc3c9664394a15fd19f6996a">serviceKey</a> = <span class="stringliteral">&quot;...&quot;</span>;</div>
<div class="line">  bindingTemplate.<a class="code" href="classuddi2____binding_template.html#ae3f7afd9f97decafd162a0c233d2480e">bindingKey</a> = <span class="stringliteral">&quot;...&quot;</span>;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Add binding Template to service</span></div>
<div class="line">  service.<a class="code" href="classuddi2____business_service.html#a87daf6bccb1d44a2d8be8fe91836404b">bindingTemplates</a> = soap_new_uddi2__bindingTemplates(soap, -1);</div>
<div class="line">  service.<a class="code" href="classuddi2____business_service.html#a87daf6bccb1d44a2d8be8fe91836404b">bindingTemplates</a>-&gt;soap_default(soap);</div>
<div class="line">  service.<a class="code" href="classuddi2____business_service.html#a87daf6bccb1d44a2d8be8fe91836404b">bindingTemplates</a>-&gt;<a class="code" href="classuddi2____binding_templates.html#ad29162175e68fa2a4f7b7dbdfb857eb0">bindingTemplate</a>.push_back(&amp;bindingTemplate);</div>
<div class="line"></div>
<div class="line">  service.<a class="code" href="classuddi2____business_service.html#abdc4aa262968386b61fe59667f0aed05">categoryBag</a> = NULL;</div>
<div class="line">  service.<a class="code" href="classuddi2____business_service.html#a552ca7cb5d3af41d5e4e86e9bb58ebb8">serviceKey</a> = <span class="stringliteral">&quot;...&quot;</span>;</div>
<div class="line">  service.<a class="code" href="classuddi2____business_service.html#a4402c59cf6e1f895522f086322f2de7f">businessKey</a> = <span class="stringliteral">&quot;...&quot;</span>;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Save the service</span></div>
<div class="line">  <a class="code" href="classuddi2____save___u_s_c_o_r_eservice.html">uddi2__save_USCOREservice</a> save_service(soap, service);</div>
<div class="line">  <a class="code" href="classuddi2____service_detail.html">uddi2__serviceDetail</a> *serviceDetail = save_service.send(server, authInfo);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Step 4: Discard authorization token</span></div>
<div class="line">  <a class="code" href="classuddi2____discard___u_s_c_o_r_eauth_token.html">uddi2__discard_USCOREauthToken</a> discard_authToken(soap, authInfo);</div>
<div class="line">  <a class="code" href="classuddi2____disposition_report.html">uddi2__dispositionReport</a> *dispositionReport = discard_authToken.send(server);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Remove deserialized objects</span></div>
<div class="line">  soap_destroy(soap);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Remove temporary data</span></div>
<div class="line">  soap_end(soap);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Detach and free context</span></div>
<div class="line">  soap_done(soap);</div>
<div class="line">  free(soap);</div>
<div class="line"></div>
<div class="line">  <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
</div><!-- fragment --><p> To compile:</p><ul>
<li>wsdl2h -tuddi2-typemap.dat publish_v2.wsdl</li>
<li>soapcpp2 -I.. -ppub publish_v2.h</li>
<li>g++ -DWITH_OPENSSL -DWITH_NONAMESPACES -I.. -o example3 example3.cpp publish_v2.cpp pubC.cpp pubClient.cpp ../stdsoap2.cpp </li>
</ul>
</div></div><!-- contents -->
<hr class="footer">
<address class="footer">
Copyright (C) 2016, Robert van Engelen, Genivia Inc., All Rights Reserved.
</address>
<address class="footer"><small>
Converted on Mon Feb 22 2016 20:01:03 by <a target="_blank" href="http://www.doxygen.org/index.html">Doxygen</a> 1.8.10</small></address>
<br>
<div style="height: 246px; background: #DBDBDB;">
</body>
</html>
